package cn.itcast.SellTicekts;

public class SellTicektThread_04 implements Runnable {

    private int ticekts = 100;
    //定义一个同步锁
    private Object object = new Object();

    @Override
    public void run() {
        while(true){
            sell();
            if(ticekts<=0){
                break;
            }
        }
    }
    public synchronized void  sell(){
        if(ticekts>0){
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"正在出第"+ticekts+"张票");
            ticekts--;
        }
    }
}
